import java.util.Scanner;

public class Test2 {
    // https://www.nowcoder.com/practice/6a7b2b6c9e3a4f56b1db9f8ca08d889b?tpId=230&tqId=38958&ru=/exam/oj
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        long[] nums = new long[n+1];
        for (int i = 1; i <= n; i++) {
            nums[i] = in.nextLong();
        }
        // 同余定义，(a+b)%k == a%k+b%k
        // dp[i][j]表示从前i个数字中选择装入,使得余数为j时背包的最大和
        long[][] dp = new long[n + 1][k];
        for (int j = 1; j < k; j++) {
            dp[0][j] = (long)-1e16;
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                dp[i][j] = Math.max(dp[i-1][j], dp[i - 1][(int)((j + (long)k - nums[i] % (long)k) % (long)k)] + nums[i]);
            }
        }
        System.out.println(dp[n][0] > 0 ? dp[n][0] : -1);
    }
}
